home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / sharewar / FFE / GRAPH.SWG / 0063_HIPS to ICC Converter Source.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-11  |  5KB  |  142 lines

  1. /*
  2. *NAME
  3. *     hipstoicc - convert hips file to icc (suitable for the kodak printer)
  4. *USAGE
  5. *     hipstoicc <in >out
  6. *DESCRIPTION
  7. *     Converts a hips file to an icc file which is suitable for the
  8. *     kodak XL7700 (true color and gray scale printer).
  9. *
  10. *     Hipstoicc handles only one frame.
  11. *
  12. *     The format for the output file is a monochrome ICC file,
  13. *     padded to 8-pixel in the column or x direction.
  14. *
  15. *     The format for the "ICC" header is:
  16. *
  17. *          Magic Number (5965600)          4 bytes
  18. *          Header Length                   4 bytes
  19. *          Extraneous data                 (Header Length -4) bytes
  20. *          Image File header length        4 bytes
  21. *          Header + data length            4 bytes
  22. *          Logical File Name              16 bytes 
  23. *          File Type (7)                   4 bytes
  24. *          Extraneous data                 8 bytes
  25. *          Image X Size                    4 bytes
  26. *          Image Y Size                    4 bytes
  27. *          Extraneous data                12 bytes
  28. *          Plane Count                     4 bytes
  29. *          Extraneous data                 8 bytes
  30. *          Extraneous data                 n bytes
  31. *          RED DATA (X_SIZE * Y_SIZE bytes)
  32. *          GREEN DATA (X_SIZE * Y_SIZE bytes) if needed
  33. *          BLUE DATA (X_SIZE * Y_SIZE bytes) if needed
  34. *
  35. *
  36. *    -Nancy Johnston, LBL - 24 Aug. 1990
  37. */
  38.  
  39. #include "hipl_format.h"
  40. #include <stdio.h>
  41. #include <time.h>         /* time defines            */
  42.  
  43. #define STDOUT 1
  44.  
  45.     /* input image declarations */
  46. unsigned char *start_in_image_buf_byte, *in_image_byte;
  47. int in_image_size_bytes ;
  48. int num_rows, num_cols, num_frames, image_size;
  49. long int x_col_pad;
  50. char *out_line;
  51. long  int header[128];         /* file header buffer */
  52. long  int clock;
  53. struct tm *date;
  54. int frame_num = 1;
  55.  
  56. char *Progname;
  57.  
  58. /*int out_fp;*/
  59.  
  60. main(argc,argv)
  61.  
  62. int argc;
  63. char **argv;
  64.  
  65. {
  66.     struct    header hd;
  67.     int i, j;
  68.  
  69.     Progname = strsave(*argv);
  70.     
  71.     read_header(&hd);
  72.     if(hd.pixel_format != PFBYTE)
  73.                 perr("pixel format must be bytes");
  74.     
  75.     num_rows = hd.rows;
  76.     num_cols = hd.cols;
  77.     x_col_pad = (num_cols + 7) & 0xfffffff8L;
  78.         /* allocated storage for one scan line */
  79.     out_line = (char *)calloc (x_col_pad, sizeof(char));
  80.     if (!out_line)
  81.     {
  82.     printf (" Could not allocated storage for scan line\n");
  83.     return (-1);
  84.     }
  85.         /* load outputted scanline with white */
  86.     for (i = 0; i < x_col_pad; ++i) out_line[i] = 255;
  87.         /* compute size of the image being read in */
  88.     image_size = num_rows * num_cols;
  89.     num_frames = hd.num_frame;
  90.     
  91.         /******  INITIALIZATION  ******/
  92.     for (i = 0; i < 128; i++)  header[i] = 0;
  93.     clock = time((long *)0);
  94.     date  = localtime(&clock);
  95.  
  96.   
  97.     header[0]  = 5965600;                        /* magic number */
  98.     header[1]  = 60;                             /* header length */
  99.     header[2]  = 0;                              /* no H/W version */
  100.     header[3]  = 0;                              /* no S/W version */
  101.                                                  /* creation date */
  102.     header[4]  = (((long)date->tm_year << 24)      & 0xff000000L) +
  103.                  (((long)(date->tm_mon + 1) << 16) & 0x00ff0000L) +
  104.                  (((long)date->tm_mday << 8)       & 0x0000ff00L) +
  105.                   ((long)date->tm_hour             & 0x000000ffL);
  106.     header[5]  = (((long)date->tm_min << 24) & 0xff000000L) +
  107.                  (((long)date->tm_sec << 16) & 0x00ff0000L);
  108.   
  109.     header[6]  = 0;                              /* no update date */
  110.     header[7]  = 0;
  111.     header[8]  = 0x64656d6fL;                    /* user name ("demo") */
  112.   
  113.     header[16] = 80;                             /* subfile header length */
  114.     header[17] = header[16] + (x_col_pad * num_rows); /* subfile length */
  115.     header[22] = 7;                              /* file type */
  116.     header[25] = num_cols;                       /* image x size */
  117.     header[26] = num_rows;                       /* image y size */
  118.     header[29] = 1;                              /* gray scale */
  119.     header[30] = 1;                              /* plane count */
  120.     write(STDOUT,header,144);
  121.   
  122.         /****** READ IN HIPS FILE ******/
  123.     start_in_image_buf_byte = (unsigned char*) halloc(image_size, sizeof (char));
  124.     in_image_byte = start_in_image_buf_byte;
  125.     in_image_size_bytes = image_size * (sizeof(char));
  126.     if ((i = pread(0, start_in_image_buf_byte, in_image_size_bytes))
  127.       != in_image_size_bytes)
  128.     perr("Unexpected end-of-file in frame number %d. %d bytes \
  129.     read for this frame.", frame_num, i);
  130.     in_image_byte = start_in_image_buf_byte; /* set pointer to start of image */
  131.  
  132.         /****** write out each row padding to 8 bits because thats what
  133.             icc or kodak wants ******/
  134.     for (i=0; i < num_rows; ++i)
  135.     {
  136.     for (j = 0; j < num_cols; j++)
  137.         out_line[j] = *in_image_byte++;
  138.     write (STDOUT, out_line, x_col_pad);
  139.     }
  140. }
  141.  
  142.